package com.example.task;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    TextView out;
    EditText edit1;
    EditText edit2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        out=findViewById(R.id.textView1);
        edit1=findViewById(R.id.wight);
        edit2=findViewById(R.id.high);
    }
    public void onClick(View v){
        String wig=edit1.getText().toString();
        String hig=edit2.getText().toString();
        double w=Double.valueOf(wig);
        double h=Double.valueOf(hig);
        String r=String.format("%.2f",w/(h*h));
        String x="";
        if(w/(h*h)<18.5){
            x=x+"您的BMI指数为："+r+"数值偏高。给您的建议是加强营养、经常运动。";
        }
        else if (w/(h*h)>=18.5&&w/(h*h)<=23.9){
            x=x+"您的BMI指数为"+r+"您的体质为正常体制，请注意保持。";
        }
        else if(w/(h*h)>23.9){
            x=x+"您的BMI指数为："+r+"数值偏高。给您的建议是减少高热量食物的摄入、控制饮食、多吃水果蔬菜。";
        }
        else {
            x=x+"请输入身高与体重";
        }
        out.setText(x);

    }
}